<template>
  <div>
    <u-form-grid :data="formGrid" ref="child">></u-form-grid>
    <Modal v-model="viewAttrs"
           title="活动属性变更"
           width="70%"
           class-name="ActivityAttrs">
      <activity-attrs :filterParams="this.formGoodsGridParams" ref="spec"></activity-attrs>
    </Modal>
  </div>
</template>

<script>
  import values from '../../utils/values'
  import moment from "moment";
  import SelectGoodsInfo from "../goods/SelectGoodsInfo.vue";
  import ActivityAttrs from "../activity/ActivityAttr.vue";

  export default {
    //众筹活动
    name: 'CouponActivity',
    components: {
      ActivityAttrs
    },
    data() {
      let sn = new moment().format("YYYYMMDDhhmmss");
      return {
        viewAttrs : false,
        formGoodsGridParams: {
          activityFullPathIds: null
        },
        //显示选择商品界面
        showSelectGoodsInfo: false,
        //

        goodsInfoId: null,
        formGrid: {
          options: {
            version: 'v2',
            url: {
              page: "/activities/couponPage",
              save: "/activities/save",
              delete: "/activities/delete",
            }
          },
          tips: {title: "众筹活动", content: "可以新建和编辑众筹活动。活动开始时间后，就会自动上架，每期众筹导到指标将自动开奖揭晓中奖者，并开启下一轮众筹活动"},
          form: {
            labelWidth:100,
            modal: {
              title: "众筹活动"
            },
            columns: [
              {label: "活动名称", type: "text", name: "name", required: true},
              {label: "活动编号", type: "text", name: "sn", required: true, init: sn,edit: {
                show: true, disabled: true
              },},
              {label: "活动组代码", type: "text", name: "groupCode", required: true},
              {label: "限购方式", type: "select", name: "limitType", required: true, data: values.limitType},
              {label: "限购份数", type: "text", name: "limitCopies", required: true},
              {label: "代金券项目编号", type: "text", name: "couponProjectCode", required: true},
              {label: "开始时间", type: "datetime", name: "startTime", required: true},
              {label: "结束时间", type: "datetime", name: "endTime", required: true},
              {label: "每日发放数量", type: "text", name: "couponActualCount", required: true},
              {label: "每张代金券金额", type: "text", name: "couponAmount", required: true},
              {label: "代金券使用开始时间", type: "date", name: "couponStartDate", required: true},
              {label: "代金券使用截止时间", type: "date", name: "couponEndDate", required: true},
              {label: "针对客户类别", type: "select", name: "couponCustomerType", required: true, data: values.couponCustomerType},
              {label: "活动状态", type: "select", name: "status", required: true, data: values.activityStatus},
              {label: "活动描述", type: "textarea", name: "remark"},
              {label: "规则说明", type: "text", name: "ruleDesc"},
            ],
            submitBefore: (data) => {
              data["type"]="代金券";
              return true;
            }
          },
          table: {
            operation: {
              primaryKey: "id",
              buttons :[
                {
                  key: "view", show: true, "label": "查看", "theme": "text", click: (row, index, _this) => {
                    _this.optViewClick(row, index);
                  }
                },
                {
                  key: "edit", show: true, "label": "编辑", "theme": "primary", click: (row, index, _this) => {
                    _this.optEditClick(row, index);
                  }
                },
                {
                  key: "delete", show: true, "label": "删除", "theme": "error", click: (row, index, _this) => {
                    _this.optDeleteClick(row, index);
                  }
                },
                {
                  key: "Attrs", show: true, "label": "属性变更", "theme": "warning", click: (row, index, _this) => {
                    this.formGoodsGridParams.activityFullPathIds = row.id;
                    this.viewAttrs = true;
                    setTimeout(() => this.$refs.spec.$emit('reloadData'));
                  }
                },
              ],
              column: {
                title: '操作',
                key: 'action',
                className: 'optColumn',
                width: 220,
              },
            },
            columns: [
              {title: '活动名称', key: 'name',renderType:"tooltip"},
              {title: '活动编号', key: 'sn',renderType:"tooltip"},
              {title: '活动组代码', key: 'groupCode',renderType:"tooltip"},
              {title: '活动开始时间', key: 'startTime',renderType:"tooltip"},
              {title: '活动结束时间', key: 'endTime',renderType:"tooltip"},
              {title: '代金券项目编号', key: 'couponProjectCode',renderType:"tooltip"},
              {title: '每日发放数量', key: 'couponActualCount',renderType:"tooltip"},
              {title: '每张代金券金额', key: 'couponAmount',renderType:"tooltip"},
              {title: '代金券使用开始时间', key: 'couponStartDate',renderType:"tooltip"},
              {title: '代金券使用截止时间', key: 'couponEndDate',renderType:"tooltip"},
              {title: '针对客户类别', key: 'couponCustomerType',renderType:"tooltip"},
              {title: '限购方式', key: 'limitType',renderType:"tooltip"},
              {title: '限购份数', key: 'limitCopies',renderType:"tooltip"},
              {title: '已领数量', key: 'couponDrawCount',renderType:"tooltip"},
              {title: "活动规则", type: "text", name: "ruleDesc",renderType:"tooltip"},
              {title: '活动状态', key: 'status',renderType:"tooltip"},
            ]
          }
        }
      }
    },
    methods: {

    }
  }
</script>
<style>
  .selectGoodsInfo{
    z-index: 2002;
  }
</style>
